<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
    <script src="https://lib.baomitu.com/jquery/2.2.4/jquery.js"></script>
    <script src="https://lib.baomitu.com/FileSaver.js/2.0.5/FileSaver.js"></script>
</head>

<body>
    <input type="button" class="ButtonLib" id="export-png" value="下载 PNG" />
    <div id="map">
    </div>
    <script>
        var docLayer = new Zondy.Map.Doc("", 'Area_Label', {
            ip: "localhost",
            port: 6163,
            /* 中地的图层也需要设置跨域参数 */
            crossOrigin: "Anonymous"
        })
        var map = new ol.Map({
            target: "map",
            layers: [gaode, docLayer],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        $("#export-png").click(function () {
            console.log(1);
            map.once('postcompose', function (event) {
                var canvas = event.context.canvas;
                canvas.toBlob(function (blob) {
                    saveAs(blob, 'map.png');
                });
            });
            map.renderSync();
        })
    </script>
</body>

</html>